import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;

import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * ${TableComment}
 *
 * @author ${Author}  ${Email}
 * @since  ${DateTime}
 */
@Tag(name="${TableComment}")
@RestController
@RequestMapping("${ClassName}")
public class ${ClassName}Controller {

  @DubboReference
  private ${ClassName}Service ${ClassName}Service;
  @Resource
  private ${ClassName}Convert convert;


  @GetMapping
  @Operation(summary = "分页条件查询")
  public Result<PagingRespVO<${ClassName}VO>> page(${ClassName}ReqVO vo) {
    ${ClassName}ReqDTO dto = convert.voToDto(vo);
    CommonRespDTO<PagingRespDTO<${ClassName}DTO>> resp = intersectionService.page(dto);
    PagingRespVO<${ClassName}VO> respVO = convert.dtoToVoPaging(resp.getData());
    return Result.success(respVO);
  }

  @PostMapping
  @Operation(summary = "新增")
  public Result<String> save(@Validated(AddGroup.class) @RequestBody ${ClassName}VO vo) {
    ${ClassName}DTO dto = convert.voToDto(vo);
    CommonRespDTO<Boolean> resp = ${ClassName}Service.save(dto);
    if (!resp.getIsOk()) {
      return Result.error(resp.getMessage());
    }
    return Result.success();
  }

  @DeleteMapping
  @Operation(summary = "删除")
  public Result<String> delete(@RequestParam String id) {
    CommonRespDTO<Boolean> resp = ${ClassName}Service.removeById(id);
    if (!resp.getIsOk()) {
      return Result.error(resp.getMessage());
    }
    return Result.success();
  }

  @PutMapping
  @Operation(summary = "修改")
  public Result<String> update(@Validated(UpdateGroup.class) @RequestBody ${ClassName}VO vo) {
        ${ClassName}DTO dto = convert.voToDto(vo);
    CommonRespDTO<Boolean> resp = ${ClassName}Service.updateById(dto);
    if (!resp.getIsOk()) {
      return Result.error(resp.getMessage());
    }
    return Result.success();
  }

}